Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unicode encoding errors in sparql processor #446 #599

Merged
merged 2 commits into from
Feb 27, 2016

Conversation

joernhees
Copy link
Member

attempt to fix #446.

The problem consist of two problems: in parserutils a SPARQLError is returned instead of raised, making it end up in operators.py, in which it ends up in another SPARQLError('... %s' % here) causing str() to be called on it... if the original expression contained a unicode char it is thus causing an encoding error:

In [7]: Exception('name was: %s' % u'jörn')
Out[7]: Exception(u'name was: j\xf6rn')

In [8]: Exception('something went wrong: %s' % Exception('name was: %s' % u'jörn'))
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-8-b264e31546f5> in <module>()
----> 1 Exception('something went wrong: %s' % Exception('name was: %s' % u'jörn'))

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 11: ordinal not in range(128)

this fixes the problem by using %r instead of %s, which might be a good idea in general.

@joernhees joernhees added bug Something isn't working enhancement New feature or request in-resolution SPARQL labels Feb 16, 2016
@joernhees joernhees self-assigned this Feb 16, 2016
@joernhees joernhees added this to the rdflib 4.2.2 milestone Feb 16, 2016
@gromgull
Copy link
Member

a SPARQLError is returned instead of raised,

this is intentional - it's a marker for a certain type of error that occured, that isn't really "exceptional"

@gromgull
Copy link
Member

we could argue that we should use a different object as error marker though, and not one that is ALSO used as an exception

@joernhees
Copy link
Member Author

yupp, it seems weird to me to return exceptions, but i already tried raising it or returning object() or None... both cause a lot of failed tests, which is why i opted to just make the exception wrapping more robust...

i think we can live with this for now and move the "don't return exceptions" part to a more boring time ;)

joernhees added a commit that referenced this pull request Feb 27, 2016
fix unicode encoding errors in sparql processor, closes #446
@joernhees joernhees merged commit 712c3fc into RDFLib:master Feb 27, 2016
@joernhees joernhees deleted the fix_sparql_unicode_filter_lang branch February 27, 2016 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request in-resolution SPARQL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnicodeEncodeError on SPARQLError
2 participants